const express = require('express');
const Mock = require('mockjs');
const app = express();  //实例化express

//post相关请求
let bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
    extended: true
}))

let router = express.Router();
//用户管理
let userApi = require("./mock/user");
//login数据引入
let loginApi = require("./mock/login");
//goods
let goodsApi = require("./mock/goods");
//oreder
let orderApi = require("./mock/order");
//system
let systemApi = require("./mock/system");
//pay
let payApi = require("./mock/pay");
//warehouse
let warehouseApi = require("./mock/warehouse");

//允许跨域
app.use(function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header('Access-Control-Allow-Headers', 'Content-Type');
    next();
});

//用户登录
app.post("/user/login", (req, res) => {
    return res.json(loginApi.login(req.body));
})
//普通用户注册
app.post("/user/sigin", (req, res) => {
    // console.log(req.body);
    return res.json(loginApi.sign(req.body));
})


//用户账户获取
app.post("/user/info", (req, res) => {
    return res.json(userApi.userInfo(req.body));
})

//重置密码
app.post("/user/reset", (req, res) => {
    return res.json(userApi.resetPassword(req.body));
})

//注册用户或者管理员 add
app.post("/user/add", (req, res) => {
    return res.json(userApi.add(req.body));
})

//冻结用户 frezz
app.post("/user/frezz", (req, res) => {
    return res.json(userApi.frezz(req.body));
})

//冻结用户 frezz
app.post("/user/unfrezz", (req, res) => {
    return res.json(userApi.unfrezz(req.body));
})

//删除用户
app.post("/user/del", (req, res) => {
    return res.json(userApi.del(req.body));
})



//1-1商品管理
app.get("/basics/goods", (req, res) => {
    return res.json(goodsApi.goodsManagment(req))
})
//1-2物流管理
app.get("/basics/logistics", (req, res) => {
    return res.json(goodsApi.goodsLogistics(req))
})
// 2-1订单管理
app.get("/order/transaction", (req, res) => {
    return res.json(orderApi.transaction(req))
})
//2-2数据统计  statistics
app.get("/order/statistics", (req, res) => {
    return res.json(orderApi.statistics(req))
})
//3-1用户管理
// systemApi   //这里暂时未做分辨管理员和用户  | 或者在渲染页"/"直接不显示
app.post("/system/user", (req, res) => {
    return res.json(systemApi.userManagment(req));
})
//4-1支付管理  payFun
app.get("/pay/fun", (req, res) => {
    return res.json(payApi.payFun(req))
})
//5-1仓库管理  /warehouse/stock
app.get("/warehouse/stock", (req, res) => {
    return res.json(warehouseApi.warehouseManagment(req))
})



app.use(router);

app.listen("3000", () => {
    console.log("3000端口已启动")
})